<?php
namespace Home\Controller;
use Think\Controller;

class IndexController extends Controller
{

    public function index()
    {
        //顶部轮播图获取
        $adTypeModel = M('plug_adtype');
        $type['plug_adtype_name'] = "首页顶部轮播";
        $adtype = $adTypeModel->where($type)->find()['plug_adtype_id'];
       // var_dump($adtype);
        $adModel = M('plug_ad');
        $condition['plug_ad_adtypeid'] = $adtype;
        $condition['plug_ad_checkid'] = 1;
        $condition['plug_ad_open'] = 1;
        $single = $adModel->field('plug_ad_pic')->order('plug_ad_order')->where($condition)->select();
       // var_dump($single);
        $this->assign('single', $single);

        //获取双层轮播图
        $adTypeModel = M('plug_adtype');
        $type['plug_adtype_name'] = "首页双层轮播";
        $adtype = $adTypeModel->where($type)->find()['plug_adtype_id'];
        $adModel = M('plug_ad');
        $condition['plug_ad_adtypeid'] = $adtype;
        $condition['plug_ad_checkid'] = 1;
        $condition['plug_ad_open'] = 1;
        $double = $adModel->field('plug_ad_pic,plug_ad_url')->order('plug_ad_order')->where($condition)->select();
        //单数就提取自身的一个元素并加进去
        $num=count($double);
        if($num%2!=0){
            $current=current($double);
            array_push($double,$current);
        }
        $this->assign('double', $double);
        $this->display();
    }
}